﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Chowpoo.Sql;
using CourseSystem.Core.Util;

namespace CourseSystem.Core.Entities
{
    [Table(Name = "Student")]
    public class StudentInfo : IDetach
    {
        public StudentInfo()
        {
            Detach();
        }
        #region Model
        private int _id;
        private string _uid;
        private string _password;
        private string _stuname;
        private int _subjectId = 0;
        private int _gradeyear = 0;
        private int _class;
        private DateTime _regdate = DateTime.Now;
        private byte _regtype = 0;
        private int _learntimes = 0;
        private string _lasturl = "";
        private int _score = -1;
        private string _lastip = "";

        private EntityRef<SubjectInfo> _subjectInfo;

        public int CollegeIdFake { get; set; }

        [System.Data.Linq.Mapping.Association(Storage = "_subjectInfo", ThisKey = "SubjectId", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public SubjectInfo SubjectInfo
        {
            get { return _subjectInfo.Entity; }
            set { _subjectInfo.Entity = value; }
        }

        private EntityRef<ClassInfo> _classInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_classInfo", ThisKey = "Class", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public ClassInfo ClassInfo
        {
            get { return _classInfo.Entity; }
            set { _classInfo.Entity = value; }
        }

        private EntityRef<GradeYearInfo> _gradeYearInfo;

        [System.Data.Linq.Mapping.Association(Storage = "_gradeYearInfo", ThisKey = "GradeYear", OtherKey = "Id", IsForeignKey = true)]
        [XmlIgnore]
        public GradeYearInfo GradeYearInfo
        {
            get { return _gradeYearInfo.Entity; }
            set { _gradeYearInfo.Entity = value; }
        }


        /// <summary>
        /// 
        /// </summary>
        [Column(IsDbGenerated = true, IsPrimaryKey = true, IsVersion = true)]
        public int Id
        {
            set { _id = value; }
            get { return _id; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("学号")]
        [Required(ErrorMessage = "必须填写")]
        public string Uid
        {
            set { _uid = value; }
            get { return _uid; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("密码")]
        public string PassWord
        {
            set { _password = value; }
            get { return _password; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("姓名")]
        [Required(ErrorMessage = "必须填写")]
        public string StuName
        {
            set { _stuname = value; }
            get { return _stuname; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("专业")]
        [NotThisValueAttr(NotValue = 0, ErrorMessage = "请选择")]
        public int SubjectId
        {
            set { _subjectId = value; }
            get { return _subjectId; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("年级")]
        [NotThisValueAttr(NotValue = 0, ErrorMessage = "请选择")]
        public int GradeYear
        {
            set { _gradeyear = value; }
            get { return _gradeyear; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        [DisplayName("班级")]
        [NotThisValueAttr(NotValue = 0, ErrorMessage = "请选择")]
        public int Class
        {
            set { _class = value; }
            get { return _class; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public DateTime RegDate
        {
            set { _regdate = value; }
            get { return _regdate; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public byte RegType
        {
            set { _regtype = value; }
            get { return _regtype; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int LearnTimes
        {
            set { _learntimes = value; }
            get { return _learntimes; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string LastUrl
        {
            set { _lasturl = value; }
            get { return _lasturl; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public int Score
        {
            set { _score = value; }
            get { return _score; }
        }
        /// <summary>
        /// 
        /// </summary>
        [Column]
        public string LastIp
        {
            set { _lastip = value; }
            get { return _lastip; }
        }
        #endregion Model

        public void Detach()
        {
            this._subjectInfo = default(EntityRef<SubjectInfo>);
            this._classInfo = default(EntityRef<ClassInfo>);
            this._gradeYearInfo = default(EntityRef<GradeYearInfo>);
        }
    }
}
